﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

namespace OS
{
    public static class LinePrinter
    {
        public static String programHeader;
        public static String programStats;
        public static List<string> outputBody = new List<string>();
        public static List<String> programOutput = new List<String>();
        public static string OUTPUT_PATH = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

        public static void PrintLine(String line)
        {
            Console.WriteLine(line);
        }

        public static void PrintCard(ProcessControlBlock pcb, String termination)
        {
            //Header
            Console.WriteLine(pcb.groupID + "       " + termination);
            
            int numSpaces = 8;
            string secondLine = "";

            for (int i = 0; i < 4 - (Convert.ToString(pcb.register_IC)).Length; i++)
            {
                secondLine += "0";
            }

            secondLine += Convert.ToString(pcb.register_IC);

            for (int i = numSpaces - secondLine.Length; i > 0; i--)
            {
                secondLine += " ";
            }
            
            secondLine += pcb.register_IR;

            for (int i = numSpaces - pcb.register_IR.Length; i > 0; i--)
            {
                secondLine += " ";
            }
            
            secondLine += pcb.register_R;

            if (pcb.register_R != null)
            {
                for (int i = numSpaces - pcb.register_R.Length; i > 0; i--)
                {
                    secondLine += " ";
                }
            }
            else
            {
                for (int i = 0; i < numSpaces; i++)
                {
                    secondLine += " ";
                }
            }

            if (pcb.toggle_C)
            {
                secondLine += "T       ";
            }
            else
            {
                secondLine += "F       ";
            }
            
            secondLine += pcb.time;

            for (int i = numSpaces - Convert.ToString(pcb.time).Length; i > 0; i--)
            {
                secondLine += " ";
            }

            secondLine += outputBody.Count;

            Console.WriteLine(secondLine);

            Console.Write("\n");

            //Body
            for (int i = 0; i < outputBody.Count; i++)
            {
                Console.WriteLine(outputBody[i]);
            }

            //New lines
            Console.Write("\n\n");
        }

        public static void Clear()
        {
            outputBody = new List<string>();
            programOutput = new List<String>();
        }

        public static String GenerateHeader1(ProcessControlBlock pcb)
        {
            //Header
            return (pcb.groupID + "       " + pcb.terminationType);
        }

        public static String GenerateHeader2(ProcessControlBlock pcb)
        {
            int numSpaces = 8;
            string secondLine = "";

            for (int i = 0; i < 4 - (Convert.ToString(pcb.register_IC)).Length; i++)
            {
                secondLine += "0";
            }

            secondLine += Convert.ToString(pcb.register_IC);

            for (int i = numSpaces - secondLine.Length; i > 0; i--)
            {
                secondLine += " ";
            }

            if (pcb.register_IR == null)
            {
                pcb.register_IR = "    ";
            }

            secondLine += pcb.register_IR;

            for (int i = numSpaces - pcb.register_IR.Length; i > 0; i--)
            {
                secondLine += " ";
            }

            secondLine += pcb.register_R;

            if (pcb.register_R != null)
            {
                for (int i = numSpaces - pcb.register_R.Length; i > 0; i--)
                {
                    secondLine += " ";
                }
            }
            else
            {
                for (int i = 0; i < numSpaces; i++)
                {
                    secondLine += " ";
                }
            }

            if (pcb.toggle_C)
            {
                secondLine += "T       ";
            }
            else
            {
                secondLine += "F       ";
            }

            secondLine += pcb.time;

            for (int i = numSpaces - Convert.ToString(pcb.time).Length; i > 0; i--)
            {
                secondLine += " ";
            }

            secondLine += pcb.lines;

            return secondLine;

        }
            
    }
}
